|
|
 |
|
|
|
|
' Define the POINTAPI type. Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function Polygon Lib "gdi32" _
Alias "Polygon" (ByVal hdc As Long, _
lpPoint As POINTAPI, ByVal nCount As Long) As Long
Private Points(1 to 10) As POINT
' (Initialize the Points array, etc.)
: Sub DrawPoly()
Polygon hDC, Points(1), 10
End Sub |
|
|
|
|
|
|
|
|
Many API routines use handles to represent objects. These handles refer to windows (HWND), device contexts (HDC), bitmaps (HBITMAP), and so forth. A handle is nothing more than an integer used to represent an object. When an API routine uses a handle, you should declare it as ByVal Long. |
|
|
|
|
|
|
|
|
Handles are not memory addresses, and you should never try to do anything directly with a handle. They are just numbers, and they have no meaning outside the functions that know how to deal with them. |
|
|
|
|
|
|
|
|
Many handles can change over time, so you should not store them in another variable for later use. Instead, get the value of the handle again each time you need to use it. |
|
|
|
|
|
|
|
|
The most important handles you use when dealing with API routines are window handles and device context handles. Forms, picture boxes, frames, text boxes, and many other controls have window handles given by their hWnd properties. A window handle represents the window that contains the form or control. |
|
|
|
|
|
|
|
|
Forms, picture boxes, and printers also have device context handles given by their hDC properties. The hDC is a handle to the device representing the form, picture box, or printer. |
|
|
|
|
|
|
|
|
Visual Basic properties are not typical variables, and you cannot always treat them like other variables when you work with API routines. You must always pass properties to API routines by value rather than by reference. If an API routine takes an argument by value, you can use the property directly. For example, the hWnd and hDC handles are usually passed by value. In the Polygon function mentioned earlier, the device context handle is passed by value, so you can use a form's hDC property directly for that argument. |
|
|
|
 |
|
|
|
|
Polygon MyForm.hDC, Points(1), 10 |
|
|
|
|
|